package info.xmlprint.action.imp;

import info.xmlprint.util.FileUtil;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.ui.wizards.datatransfer.ExternalProjectImportWizard;

public class ImportXmlp extends ExternalProjectImportWizard {
	BasicImportPage mainPage;

	public void addPages() {
		mainPage = new BasicImportPage();
		mainPage.setTitle("Import");
		mainPage.setDescription("Select a xmlp file into workspace");
		mainPage.setFilterExtension(new String[] { "*.xmlp" });
		mainPage.setExportDialogTitle("Import from xmlp file");
		addPage(mainPage);
	}

	public boolean performFinish() {
		if (mainPage.validExportFile()) {
			String input = mainPage.getFilePath();
			String name = mainPage.getProjectName();
			IProject project = ResourcesPlugin.getWorkspace().getRoot()
					.getProject(name);

			try {
				project.create(null);
				project.open(null);
			} catch (CoreException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			FileUtil.zip2Project(input, project, false);
			return true;

		} else {
			return false;
		}
	}

	public boolean performCancel() {
		return true;
	}
}